package test05;

// 1. 抽象组件接口
interface Character {
    void show();
    String getDescription();
}

// 2. 具体组件 - 基础人物
class BaseCharacter implements Character {
    private String name;

    public BaseCharacter(String name) {
        this.name = name;
    }

    @Override
    public void show() {
        System.out.println("角色: " + name);
    }

    @Override
    public String getDescription() {
        return "基础角色: " + name;
    }
}

// 3. 抽象装饰器
abstract class ClothingDecorator implements Character {
    protected Character decoratedCharacter;

    public ClothingDecorator(Character character) {
        this.decoratedCharacter = character;
    }

    @Override
    public void show() {
        decoratedCharacter.show();
    }

    @Override
    public String getDescription() {
        return decoratedCharacter.getDescription();
    }
}

// 4. 具体装饰器 - 衬衫
class ShirtDecorator extends ClothingDecorator {
    private String style;

    public ShirtDecorator(Character character, String style) {
        super(character);
        this.style = style;
    }

    @Override
    public void show() {
        super.show();
        System.out.println("  穿着: " + style + "衬衫");
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " + " + style + "衬衫";
    }
}

// 5. 具体装饰器 - 裤子
class PantsDecorator extends ClothingDecorator {
    private String type;

    public PantsDecorator(Character character, String type) {
        super(character);
        this.type = type;
    }

    @Override
    public void show() {
        super.show();
        System.out.println("  穿着: " + type + "裤子");
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " + " + type + "裤子";
    }
}

// 6. 具体装饰器 - 帽子
class HatDecorator extends ClothingDecorator {
    private String hatType;

    public HatDecorator(Character character, String hatType) {
        super(character);
        this.hatType = hatType;
    }

    @Override
    public void show() {
        super.show();
        System.out.println("  戴着: " + hatType + "帽子");
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " + " + hatType + "帽子";
    }
}

// 7. 具体装饰器 - 鞋子
class ShoesDecorator extends ClothingDecorator {
    private String shoeStyle;

    public ShoesDecorator(Character character, String shoeStyle) {
        super(character);
        this.shoeStyle = shoeStyle;
    }

    @Override
    public void show() {
        super.show();
        System.out.println("  穿着: " + shoeStyle + "鞋子");
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " + " + shoeStyle + "鞋子";
    }
}

// 8. 具体装饰器 - 外套
class CoatDecorator extends ClothingDecorator {
    private String coatStyle;

    public CoatDecorator(Character character, String coatStyle) {
        super(character);
        this.coatStyle = coatStyle;
    }

    @Override
    public void show() {
        super.show();
        System.out.println("  穿着: " + coatStyle + "外套");
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " + " + coatStyle + "外套";
    }
}

// 9. 客户端测试类
public class DressUpGame {
    public static void main(String[] args) {
        System.out.println("=== 换装游戏开始 ===\n");

        // 创建基础角色
        Character person = new BaseCharacter("小明");

        // 第一次换装
        System.out.println("--- 第一套装扮 ---");
        person = new ShirtDecorator(person, "白色T恤");
        person = new PantsDecorator(person, "蓝色牛仔裤");
        person = new ShoesDecorator(person, "运动鞋");
        person.show();
        System.out.println("完整描述: " + person.getDescription());

        // 第二次换装 - 在原有基础上添加更多服饰
        System.out.println("\n--- 添加帽子和外套 ---");
        person = new HatDecorator(person, "棒球帽");
        person = new CoatDecorator(person, "牛仔外套");
        person.show();
        System.out.println("完整描述: " + person.getDescription());

        // 创建新角色进行不同的装扮
        System.out.println("\n--- 新角色装扮 ---");
        Character person2 = new BaseCharacter("小红");
        person2 = new ShirtDecorator(person2, "连衣裙");
        person2 = new HatDecorator(person2, "遮阳帽");
        person2 = new ShoesDecorator(person2, "高跟鞋");
        person2.show();
        System.out.println("完整描述: " + person2.getDescription());

        // 演示多层装饰
        System.out.println("\n--- 多层装饰演示 ---");
        Character person3 = new BaseCharacter("小刚");
        person3 = new ShirtDecorator(person3, "背心");
        person3 = new ShirtDecorator(person3, "衬衫"); // 在背心外面穿衬衫
        person3 = new ShirtDecorator(person3, "毛衣"); // 在衬衫外面穿毛衣
        person3 = new CoatDecorator(person3, "风衣");  // 最外面穿风衣
        person3.show();
        System.out.println("完整描述: " + person3.getDescription());
    }
}